package org.azmat.mybatis.SQL.uilt;

import org.azmat.mybatis.SQL.Entity.Book;
import org.apache.ibatis.jdbc.SQL;

public class SqlContext {

    public static String searchBook(final Book book) {
        return new SQL() {{
            SELECT("*");
            FROM("book");

            if (book.getName() != null && !book.getName().isEmpty()) {
                WHERE("name like '%' #{name}' %'");
            }
            if (book.getCategory() != null && !book.getCategory().isEmpty()) {
                WHERE("category = #{category}");
            }
            if (book.getAuthor() != null && !book.getAuthor().isEmpty()) {
                WHERE("author LIKE '%'#{author}'%'");
            }
        }}.toString();
    }
}
